package com.quanyan.common.utils;


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by xiao.lai on 2015/9/2.
 *
 *
 */
public class CookieUtils {


   /* *//**
     * 获取cookie的value
     *
     * *//*
    public static String getCookie(HttpServletRequest request, String name) throws  Exception {
        String result = null;
        int n = name.length();
        Cookie[] cookies = request.getCookies();
        if(cookies!=null)
        {
            for (int i = 0; i < cookies.length; i++)
            {
                Cookie c = cookies[i];
                if(c.getName().substring(0, n).equalsIgnoreCase(name))
                {
                    result = c.getValue();
                    result =new String(result.getBytes("ISO8859_1"),"utf-8");
                    System.out.println(result);
                }
            }
        }
        return result;
    }*/

    /**
     * 存储cookie
     *
     * */
    public static void setCookie(HttpServletResponse response, String key, String value) throws  Exception {
        //更新cookie
        try {
            String domain = PropUtils.getProperty("app.domain");
            Cookie cookie = new Cookie(key, value);
            cookie.setDomain(domain);
            cookie.setMaxAge(3600 * 24 * 7);
            response.addCookie(cookie);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
